#include "Collider.h"

void Physics::Collider::SetOffsetTransform(const glm::vec3 &pos, const glm::quat &rot)
{
    rp3d::Transform transform;
    transform.setPosition(RP_VEC3(pos));
    transform.setOrientation(RP_QUAT(rot));
    m_Impl->setLocalToBodyTransform(transform);
}

void Physics::Collider::GetOffsetTransform(glm::vec3 &pos, glm::quat &rot)
{
    rp3d::Transform transform = m_Impl->getLocalToBodyTransform();
    pos = GLM_VEC3(transform.getPosition());
    rot = GLM_QUAT(transform.getOrientation());

}

bool Physics::Collider::IsTrigger()
{
    return m_Impl->getIsTrigger();
}

void Physics::Collider::SetIsTrigger(bool v)
{
    this->m_Impl->setIsTrigger(v);
}

void Physics::Collider::SetMaterialValue(float bounciness, float frictionCoeff, float massDensity)
{
    rp3d::Material material = this->m_Impl->getMaterial();
    material.setBounciness(bounciness);
    material.setFrictionCoefficient(frictionCoeff);
    material.setMassDensity(massDensity);
    m_Impl->setMaterial(material);
    
}

void Physics::Collider::GetMaterialValue(float &bouncines, float &frictionCoeff, float &massDensity) const
{
    rp3d::Material material = this->m_Impl->getMaterial();
    bouncines = material.getBounciness();
    frictionCoeff = material.getFrictionCoefficient();
    massDensity = material.getMassDensity();
}

Physics::Material Physics::Collider::GetMaterial() const
{
    Physics::Material material;
    GetMaterialValue(material.bounciness, material.frictionCoeff, material.massDensity);
    return material;
}

void Physics::Collider::SetMaterial(const Physics::Material &material)
{
    this->SetMaterialValue(material.bounciness, material.frictionCoeff, material.massDensity);
}

unsigned short Physics::Collider::GetCollideWithMaskBits()
{
    return this->m_Impl->getCollideWithMaskBits();
}

unsigned short Physics::Collider::GetCollisionCategoryBits()
{
    return this->m_Impl->getCollisionCategoryBits();
}
void Physics::Collider::SetCollideWithMaskBits(const unsigned short &maskBits)
{
    this->m_Impl->setCollideWithMaskBits(maskBits);
}

void Physics::Collider::SetCollisionCategoryBits(const unsigned short maskBits)
{
    this->m_Impl->setCollisionCategoryBits(maskBits);

}

Physics::Collider::Collider(rp3d::Collider *impl)
    : m_Impl(impl)
{
}